<?php
function derived_excel($successful_personnel){

        import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Writer.Excel2007");
        import("Org.Util.PHPExcel.Writer.Excel5");
        import("Org.Util.PHPExcel.IOFactory");
        
        $objPHPExcel = new \PHPExcel();
        
        // 设置表头
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '编号')
                                            ->setCellValue('B1', '姓名')
                                            ->setCellValue('C1', '学号')
                                            ->setCellValue('D1', '邮箱')
                                            ->setCellValue('E1', '电话号码')
                                            ->setCellValue('F1', '加入时间');
        // 循环输出数据到excel对应的位置
        foreach($successful_personnel as $k => $v){
            $num=$k+2;
      
            $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$num, $num-1)
                        ->setCellValue('B'.$num, $v['realname'])
                        ->setCellValue('C'.$num, $v['stunum'])
                        ->setCellValue('D'.$num, $v['email'])
                        ->setCellValue('E'.$num, $v['phone'])
                        ->setCellValue('F'.$num, $v['joindate']);
            }
        // 屌丝的设计： 设置单格宽度，不能再一个里面写，  setWidth 即为设置 固定长度    setAutoSize 即为自动但是有时不准
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(5);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(9);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setAutoSize(true);
        
        $this_time = date('Y-m-d', time());                                                 // 获取当日日期
        $objPHPExcel->getActiveSheet()->setTitle("$this_time");                             // 设置分页sheet的名字
        $objPHPExcel->setActiveSheetIndex(0);                                               // 设置默认打开那个分页
        header('Content-Type: application/vnd.ms-excel');                                   // 设置输出的是什么东西，即excel
        header('Content-Disposition: attachment;filename="'.$this_time._全部导出数据.'.xls"'); // 为文件赋予名字
        header('Cache-Control: max-age=0');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');              // 调用静态方法
        $objWriter->save('php://output');                                                   // 输出到浏览器
        exit;

}
function getpage($count, $pagesize ) {
    $p = new Think\Page($count, $pagesize);
    $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
    $p->setConfig('prev', '上一页');
    $p->setConfig('next', '下一页');
    $p->setConfig('last', '末页');
    $p->setConfig('first', '首页');
    $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
    $p->lastSuffix = false;//最后一页不显示为总页数
    return $p;
}